#include <stdio.h>
#include <stdlib.h>

int UpTrangleR(int *arr, int n) {
    for (int i = n; i < n * n; i += n) {
        for (int j = 0; j < i / n; j++) {
            if (arr[i + j] != 0) {
                return 0;
            }
        }
    }
    return 1;
}

int UpTrangleL(int *arr, int n) {
    for (int i = 2 * n - 1; i < n * n; i += n) {
        for (int j = 0; j < i / n; j++) {
            if (arr[i - j] != 0) {
                return 0;
            }
        }
    }
    return 1;
}

typedef struct Flexible {
    int N;
    int Mat[0];
}Flexible;

int main() {
    int n = 0;
    scanf("%d", &n);
    //创建柔性数组
    Flexible *arr = (Flexible *) malloc(sizeof(Flexible) + n * n * sizeof(int));
    if (arr == NULL) {
        perror("堆区开辟空间失败:");
    }
    arr->N = n * n;
    //柔性数组的使用
    for (int i = 0; i < arr->N; i++) {
        scanf("%d", &arr->Mat[i]);
    }
    int ret = UpTrangleL(arr->Mat, n) + UpTrangleR(arr->Mat, n);

    if (ret >= 1) {
        printf("YES");
    } else {
        printf("NO");
    }
    //释放柔性数组
    free(arr);
    arr = NULL;
    return 0;
}